package crons

import (
	"context"
	"go.didapinche.com/foundation/plat-echo/app/ops/services"
	"go.uber.org/zap"
)

//todo
type ApiDataJob struct {
	logger  *zap.Logger
	service services.ApiDataService
}

func NewApiDataJob(logger *zap.Logger, apiService services.ApiDataService) *ApiDataJob {
	job := &ApiDataJob{
		logger:  logger,
		service: apiService,
	}
	return job
}

func (a *ApiDataJob) Run() {
	a.logger.Info("collect api data  start")
	ctx := context.Background()
	err := a.service.CollectDataHttp(ctx)
	if err != nil {
		a.logger.Error("call  CollectDataHttp run error", zap.Error(err))
	}
	err = a.service.CollectDataZeus(ctx)
	if err != nil {
		a.logger.Error("call CollectDataZeus run error", zap.Error(err))
	}
	a.logger.Info("collect api data end")
}

func (a *ApiDataJob) Cron() string {
	return "0 */10 * * * ?"
}

func (a *ApiDataJob) Name() string {
	return "api_data_job"
}
